/**
 * 
 */
package com.pengtu.dao.detect.grade;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Component;

import com.pengtu.dao.hibernate.HibernateDao;
import com.pengtu.entity.detect.grade.Subentry;

/**
 * @author Administrator
 *
 */
@Component
public class SubentryCheckDao  extends HibernateDao<Subentry, Serializable>{

	//查找施工合同段下的所有分项
	public List<Subentry> findBySignProj(String  signprojId){
		String hql = "SELECT sub.* FROM t_q_grade_subentry sub,  t_q_grade_branch branch  ," +
				   " t_q_grade_unitproj  unit , t_q_grade_signprojquacheck signcheck , " + 
				   " T_PROJ_SIGNUPCONTRACT signproj  WHERE sub.branchid = branch.id and " +
				   "branch.unitprojid=unit.id and unit.signprojid = signcheck.id and " +
				   "signcheck.signcontructid =signproj.id " +
				   " and signproj.id = '"+signprojId+"'";
		return super.getSession().createSQLQuery(hql).addEntity(Subentry.class).list();
	}
	//查找施工合同段下的所有分项
	public List<Subentry> findBySigncheck(String  signcheckId){
		String hql = "SELECT sub.* FROM t_q_grade_subentry sub,  t_q_grade_branch branch  ," +
				   " t_q_grade_unitproj  unit , t_q_grade_signprojquacheck signcheck  " + 
				   " WHERE sub.branchid = branch.id and " +
				   "branch.unitprojid=unit.id and unit.signprojid = signcheck.id  " +
				   " and signcheck.id = '"+signcheckId+"'";
		return super.getSession().createSQLQuery(hql).addEntity(Subentry.class).list();
	}
	
	
	public void deleteBySigncheckId(String  signcheckId , String subCode){
		String hql = "delete sub.* FROM t_q_grade_subentry sub,  t_q_grade_branch branch  ," +
				   " t_q_grade_unitproj  unit , t_q_grade_signprojquacheck sign " + 
				   " WHERE sub.branchid = branch.id and branch.unitprojid=unit.id and unit.signprojid = " +
				   " sign.id and sign.id = '"+signcheckId+"' and sub.subentrycode = '"+subCode+"' ";
		 super.getSession().createQuery(hql).executeUpdate();
	}

	@Override
	public void delete(Subentry entity) {
		// TODO Auto-generated method stub
		getSession().delete(entity);
	}
	
	
}
